
package com.gitee.jmash.storage.client;

import com.gitee.jmash.common.grpc.auth.OAuth2Credentials;
import com.gitee.jmash.common.grpc.client.GrpcChannel;
import com.gitee.jmash.rbac.client.token.SystemAccessToken;
import jmash.storage.StorageGrpc;

/** Storage Client . */
public class StorageClient {

  /** StorageBlockingStub. */
  public static StorageGrpc.StorageBlockingStub getStorageBlockingStub() {
    return StorageGrpc.newBlockingStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(GrpcChannel.getCallCredentials());
  }

  /** StorageFutureStub. */
  public static StorageGrpc.StorageFutureStub getStorageFutureStub() {
    return StorageGrpc.newFutureStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(GrpcChannel.getCallCredentials());
  }

  /** StorageStub. */
  public static StorageGrpc.StorageStub getStorageStub() {
    return StorageGrpc.newStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(GrpcChannel.getCallCredentials());
  }


  /** StorageBlockingStub. */
  public static StorageGrpc.StorageBlockingStub getStorageSystemBlockingStub(String tenant) {
    return StorageGrpc.newBlockingStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(getSystemCredentials(tenant));
  }

  /** StorageFutureStub. */
  public static StorageGrpc.StorageFutureStub getStorageSystemFutureStub(String tenant) {
    return StorageGrpc.newFutureStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(getSystemCredentials(tenant));
  }

  /** StorageStub. */
  public static StorageGrpc.StorageStub getStorageSystemStub(String tenant) {
    return StorageGrpc.newStub(StorageClientConfig.getManagedChannel())
        .withCallCredentials(getSystemCredentials(tenant));
  }

  /** 获取系统访问凭证. */
  public static OAuth2Credentials getSystemCredentials(String tenant) {
    String accessToken = SystemAccessToken.getAccessToken(tenant);
    return new OAuth2Credentials(accessToken);
  }

}
